package base;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 王霄
 * @date 2022/9/19 13:45
 */
public class FileReadLineDemo {

    public static void main(String[] args) throws IOException {
        var filePath = "C:\\code\\java\\src\\main\\resources\\type.txt";
        List<String> list = readLineAsList(filePath);

        String sql = "INSERT INTO `dm_device_type`(`id`, `name`, `main_img`, `remark`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (NULL, '%s', NULL, NULL, '', '2022-09-17 00:00:00', '', '2022-09-17 00:00:00');";
        for (String s : list) {
            String a = String.format(sql, s);
            System.out.println(a);
        }
    }

    private static List<String> readLineAsList(String filePath) throws IOException {
        List<String> list = new ArrayList<>();
        var inputStream = new FileReader(filePath, StandardCharsets.UTF_8);
        var reader = new BufferedReader(inputStream);
        String line;
        while ((line = reader.readLine()) != null) {
            list.add(line);
        }
        reader.close();
        return list;
    }

}
